
package com.kugou.game.sdk.adapter;

import com.kugou.game.sdk.entity.PayRecord;
import com.kugou.game.sdk.utils.Rx;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class CostRecordsBaseAdater extends BaseAdapter {
    private Context context;

    private ArrayList<PayRecord> mArrayList;

    public CostRecordsBaseAdater(Context context, ArrayList<PayRecord> mArrayList) {
        this.context = context;
        this.mArrayList = mArrayList;
    }

    public void refreshData(ArrayList<PayRecord> arrayList) {
        this.mArrayList = arrayList;
    }

    @Override
    public int getCount() {
        return mArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return mArrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(Rx.layout.kg_item_charge_history_list, null);
            holder.tvTime = (TextView) convertView.findViewById(Rx.id.kg_tv_time);
            holder.tvMoney = (TextView) convertView.findViewById(Rx.id.kg_tv_money);
            holder.tvOption = (TextView) convertView.findViewById(Rx.id.kg_tv_option);
            holder.tvType = (TextView) convertView.findViewById(Rx.id.kg_tv_type);
            holder.tvBottomLine = (TextView) convertView.findViewById(Rx.id.kg_view_bottom_line);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position == getCount() - 1) {
            holder.tvBottomLine.setVisibility(View.VISIBLE);
        } else {
            holder.tvBottomLine.setVisibility(View.GONE);
        }

        PayRecord payRecord = mArrayList.get(position);
        holder.tvMoney.setText(payRecord.getMoney());
        holder.tvOption.setText(payRecord.getPayOption());
        holder.tvType.setText("通过" + payRecord.getPayType());
        String payTime ="";
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = sdf.parse(payRecord.getPayTime());
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
            payTime = sdf1.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        holder.tvTime.setText(payTime);
        return convertView;
    }

    class ViewHolder {

        public TextView tvTime;

        public TextView tvMoney;

        public TextView tvOption;

        public TextView tvType;

        public TextView tvBottomLine;
    }
}
